﻿/**********************************天使物流*******************************************
* 功能描述:菜单
* 作者:孟帅龙
* 时间:2022/1/7
* 
**********************************天使物流*******************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TianShiProject.EntityFrameworkCore;
using TianShiProject.Models.Common;
using TianShiProject.Models.System;
using TianShiProject.Models.System.Menus;
using Volo.Abp.EntityFrameworkCore;

namespace TianShiProject.System.Menus
{
    public class MenuRepository : DapperDbContextRepository, IMenuRepository
    {
        public MenuRepository(IDbContextProvider<TianShiProjectDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        #region 菜单
        public List<MenuDto> MenuShow(List<MenuDto> list, string menuNumber = "")
        {
            return list.Where(p => p.ParentMenuId == menuNumber).Select(t => new MenuDto
            {
                Id = t.Id,
                MenuName= t.MenuName,
                Url = t.Url,
                Icon=t.Icon,
                IsDelete=t.IsDelete,
                Level=t.Level,
                MenuNumber=t.MenuNumber,
                ParentMenuId= t.ParentMenuId,
                ChildMenus=MenuShow(list, t.MenuNumber).Count==0?null:MenuShow(list,t.MenuNumber)
            }).ToList();
        }
        #endregion

        #region 菜单显示
        public async Task<List<MenuDto>> GetMenus()
        {
            var list = await this.QueryAsync<MenuDto>("select * from Menu where IsDelete=0");
            return MenuShow(list).ToList();
        }
        #endregion
    }
}
